import { queryCustomerListService } from '@/api/commodity/common';
export default {
  data () {
    return {
      formData: {
        customerCode: '',
        customerId: '',
        customerName: ''
      },
      dialogVisible: {
        customer: false
      }
    }
  },
  methods: {
    // 选择客户
    handleChooseCustomer () {
      console.log(1)
      this.dialogVisible.customer = true;
    },
    // 远程搜索客户
    async remoteOptionsByCustomer (queryString, loadingFn) {
      const data = { searchParam: queryString, pageShow: 20 };
      const retData = await queryCustomerListService(data, loadingFn);
      if (retData) return retData.result ?? [];
      return [];
    },
    // 获取远程搜索选择的客户信息
    getCustomerInfoByRemote (data) {
      this.setCustomerInfo(data);
    },
    // 获取弹框选择的客户信息
    getCustomerInfoByDialog (data) {
      this.setCustomerInfo(data);
    },
    // 设置客户信息
    setCustomerInfo (data) {
      this.formData.customerId = data.customerId;
      this.formData.customerCode = data.customerCode;
      this.formData.customerNo = data.customerCode;
      this.formData.customerName = data.customerName;
    },
    // 清空客户信息
    clearCustomerInfo () {
      this.formData.customerId = '';
      this.formData.customerCode = '';
      this.formData.customerName = '';
      this.$refs.remoteSelect.clearValue()
    }
  }
}
